<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
class IndexController extends AppController
{
    public function index(){
        $this->assign('title', '后台管理');
        if($this->checkIsAdmin()) {
            $allot_arr = AdminActionModel::load()->get_menu();
        } else {
            $allot_arr = AdminUserModel::load()->get_allot_array($this->user_id);     
            mylog_debug($allot_arr, '用户权限');
        }      
        if($allot_arr) {
            $allot_str = implode(',', $allot_arr);
            $menu_arr = AdminActionModel::load()->get_user_menu($allot_str);
            mylog_debug($menu_arr, '用户权限-带菜单的1');
            $menu_new = array();
            foreach ($menu_arr as $main_menu) {
                if($main_menu['parent_id'] == 0) {
                    $menu_new[] = $main_menu;
                }
            }
            foreach ($menu_new as $key => $menu) {
                foreach ($menu_arr as $child_menu) {
                    if($child_menu['parent_id'] == $menu['action_id']) {
                        $menu_new[$key]['child'][] = $child_menu;
                    }
                }
            }
            $this->assign('menu_data', $menu_new);
        }        
        $this->display('index');
    }
    /**
     * 首页信息
     */
    public function info(){        
        $this->display('info');
    }
}
